<template>
  <view v-if="shenheStatus == 0" class="checkShop">
    <!-- <view class="header-tabs">
      <u-tabs
        :list="tabList"
        :current="current"
        active-color="#FA230A"
        item-width="25%"
        @change="tabsChange"
        height="44"
        inactive-color="#262626"
      ></u-tabs>
    </view>
    <view class="shopList">
      <view class="shopItem" v-for="(item, index) in shopList" :key="index">
        <view class="title">
          <view class="name">
            <text class="iconfont icon-store"></text>
            <text>{{ item.name }}</text>
          </view>
          <text class="status">
            {{ shopStatus(item) }}
          </text>
        </view>
        <view class="info">
          <text>{{ item.mobile }}</text>
          <text>{{ item.cat_name }}</text>
        </view>
        <view class="btns">
          <text v-if="item.status == 0" @click="checkShop(item.id, 2)"
            >{{$t('salesman.refuse')}}</text
          >
          <text
            class="red"
            v-if="item.status == 0"
            @click="checkShop(item.id, 1)"
            >{{$t('salesman.agree')}}</text
          >
          <text
            class="red"
            v-if="item.status == 1 && item.merchant_status != 3"
            @click="toApplication(item)"
            >{{$t('salesman.pay')}}</text
          >
        </view>
      </view>
      <view class="empty" style="padding-top:50rpx;">
        <u-empty mode="data" v-if="!shopList.length"></u-empty>
      </view>
    </view> -->

    <view class="tabs">
      <view
        :class="['tabItem', current == 0 ? 'choosed' : '']"
        @click="changeTab(0)"
        >待审核({{ checkNum || 0 }})</view
      >
      <view
        :class="['tabItem', current == 1 ? 'choosed' : '']"
        @click="changeTab(1)"
        >待完善({{ completeNum || 0 }})</view
      >
      <view
        :class="['tabItem', current == 2 ? 'choosed' : '']"
        @click="changeTab(2)"
        >已完成</view
      >
    </view>
    <view class="query">
      <view
        :class="['queryItem', showQuery && queryType == 1 ? 'choosed' : '']"
        @click="
          showQuery = true;
          queryType = 1;
        "
      >
        <text v-if="queryParam.sort == 0">创建时间</text>
        <text v-if="queryParam.sort == 1">审核时间</text>
        <text v-if="queryParam.sort == 2">完成时间</text>
        <text
          class="iconfont icon-arrow-up-filling"
          v-if="showQuery && queryType == 1"
        ></text>
        <text class="iconfont icon-arrow-down-filling" v-else></text>
      </view>
      <view
        :class="['queryItem', showQuery && queryType == 2 ? 'choosed' : '']"
        @click="
          showQuery = true;
          queryType = 2;
        "
      >
        <text>{{ !queryParam.category_id ? '店铺分类' : catName }}</text>
        <text
          class="iconfont icon-arrow-up-filling"
          v-if="showQuery && queryType == 2"
        ></text>
        <text class="iconfont icon-arrow-down-filling" v-else></text>
      </view>
      <view
        :class="['queryItem', showQuery && queryType == 3 ? 'choosed' : '']"
        @click="
          showQuery = true;
          queryType = 3;
        "
      >
        <text v-if="!queryParam.type">小程序类型</text>
        <text v-if="queryParam.type == 1">微信小程序</text>
        <text v-if="queryParam.type == 2">支付宝小程序</text>
        <text
          class="iconfont icon-arrow-up-filling"
          v-if="showQuery && queryType == 3"
        ></text>
        <text class="iconfont icon-arrow-down-filling" v-else></text>
      </view>
    </view>
    <view class="storeList">
      <storeItem
        :status="current"
        v-for="item in shopList"
        :key="item.id"
        :store="item"
        @audit="initList"
      ></storeItem>
      <u-empty text="暂无数据~" mode="list" v-if="!shopList.length"></u-empty>
    </view>
    <view
      class="chooseBox"
      @click="
        showQuery = false;
        queryType = '';
      "
      v-if="showQuery"
    >
      <view class="options">
        <template v-if="queryType == 1">
          <view
            :class="['optionItem', queryParam.sort == 0 ? 'choosed' : '']"
            @click.stop="chooseSort(0)"
          >
            <text>创建时间</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.sort == 0"
            ></text>
          </view>
          <view
            :class="['optionItem', queryParam.sort == 1 ? 'choosed' : '']"
            @click.stop="chooseSort(1)"
          >
            <text>审核时间</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.sort == 1"
            ></text>
          </view>
          <view
            :class="['optionItem', queryParam.sort == 2 ? 'choosed' : '']"
            @click.stop="chooseSort(2)"
          >
            <text>完成时间</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.sort == 2"
            ></text>
          </view>
        </template>
        <template v-if="queryType == 2">
          <view
            :class="[
              'optionItem',
              queryParam.category_id == item.id ? 'choosed' : '',
            ]"
            v-for="item in catList"
            :key="item.id"
            @click="chooseCat(item)"
          >
            <text>{{ item.name }}</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.category_id == item.id"
            ></text>
          </view>
        </template>
        <template v-if="queryType == 3">
          <view
            :class="['optionItem', queryParam.type == 1 ? 'choosed' : '']"
            @click.stop="chooseType(1)"
          >
            <text>微信小程序</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.sort == 1"
            ></text>
          </view>
          <view
            :class="['optionItem', queryParam.type == 2 ? 'choosed' : '']"
            @click.stop="chooseType(2)"
          >
            <text>支付宝小程序</text>
            <text
              class="iconfont icon-seleted"
              v-if="queryParam.sort == 2"
            ></text>
          </view>
        </template>
      </view>
    </view>
  </view>
  <Shenhe v-else-if="shenheStatus == 1"></Shenhe>
</template>

<script>
import Shenhe from '@/components/shenhe/shenhe';
import storeItem from './components/storeItem.vue';
export default {
  components: {
    storeItem,
    Shenhe,
  },
  data() {
    return {
      tabList: [
        {
          name: this.$t('person.cashStatus1'),
          status: 0,
        },
        {
          name: this.$t('person.cashStatus2'),
          status: 1,
        },
        {
          name: this.$t('salesman.status1'),
          status: 2,
        },
        {
          name: this.$t('person.status4'),
          status: 3,
        },
      ],
      // 当前tab所处项
      current: 0,
      // 当前所在页面
      page: 1,
      // 是否加载完毕
      noMore: false,
      // 店铺列表
      shopList: [],
      // 显示选择筛选条件的盒子
      showQuery: false,
      // 筛选参数
      queryParam: {
        category_id: '',
        type: '',
        sort: '0',
      },
      // 分类名称
      catName: '',
      // 筛选盒子的类型 1时间  2分类 3小程序类型
      queryType: '',
      // 所有分类列表
      catList: [],
      // 待审核数量
      checkNum: 0,
      // 待完善数量
      completeNum: 0,
    };
  },
  methods: {
    // 切换导航
    tabsChange(e) {
      this.page = 1;
      this.shopList = [];
      this.noMore = false;
      this.current = e;
      this.getList();
    },
    // 获取审核店铺列表
    async getList() {
      const res = await this.$allrequest.merchant.auditList({
        page: this.page,
        status: this.current,
        category_id: this.queryParam.category_id,
        type: this.queryParam.type,
        sort: this.queryParam.sort,
      });
      if (res.code == 0) {
        this.catList = res.data.category;
        this.checkNum = res.data.examine;
        this.completeNum = res.data.repair;
        this.shopList = [...this.shopList, ...res.data.list];
        if (this.shopList.length >= res.data.row_count) {
          this.noMore = true;
        } else {
          this.noMore = false;
        }
      }
    },
    // 跳转进件申请页面
    toApplication(e) {
      if (e.from == 0) {
        uni.navigateTo({
          url: '/salesman/application/application?id=' + e.merchant_info_id,
        });
      }
      if (e.from == 1) {
        uni.navigateTo({
          url: '/salesman/application/chooseType?id=' + e.merchant_info_id,
        });
      }
    },
    // 审核店铺
    checkShop(id, status) {
      let text =
        status == 1 ? this.$t('salesman.agree') : this.$t('salesman.refuse');
      uni.showModal({
        title: this.$t('list.confirm') + text + this.$t('salesman.store'),
        showCancel: true,
        cancelText: this.$t('person.cancle'),
        cancelColor: '#000000',
        confirmText: this.$t('list.confirm'),
        confirmColor: '#3CC51F',
        success: async result => {
          if (result.confirm) {
            const res = await this.$allrequest.merchant.audit(
              {
                id,
                status,
              },
              true
            );
            if (res.code == 0) {
              this.page = 1;
              this.shopList = [];
              this.noMore = false;
              this.getList();
            }
          }
        },
      });
    },
    // 初始化数据
    initList(flag) {
      this.page = 1;
      this.shopList = [];
      if (flag) {
        this.queryParam.category_id = '';
        this.queryParam.type = '';
        this.catName = '';
      }
      this.noMore = false;
      this.getList();
    },
    // 切换导航
    changeTab(e) {
      if (e == this.current) {
        return;
      }
      this.current = e;
      this.initList();
    },
    // 选择筛选时间
    chooseSort(e) {
      if (e == this.queryParam.sort) {
        return;
      }
      this.queryParam.sort = e;
      this.showQuery = false;
      this.queryType = '';
      this.initList();
    },
    // 选择分类
    chooseCat(e) {
      if (e.id == this.queryParam.category_id) {
        return;
      }
      this.queryParam.category_id = e.id;
      this.catName = e.name;
      this.queryType = '';
      this.showQuery = false;
      this.initList();
    },
    // 选择小程序类型
    chooseType(e) {
      if (e == this.queryParam.type) {
        return;
      }
      this.queryParam.type = e;
      this.showQuery = false;
      this.queryType = '';
      this.initList();
    },
  },
  onLoad(t) {
    if (t.status) {
      this.current = t.status - 0;
    }
    this.getList();
  },
  computed: {
    shopStatus() {
      return item => {
        if (item.status == 0) {
          return this.$t('person.cashStatus2');
        } else if (item.status == 1) {
          if (item.merchant_status == 3) {
            return this.$t('person.status4');
          } else {
            return this.$t('salesman.status1');
          }
        } else if (item.status == 2) {
          return this.$t('shareholder.refuced');
        }
      };
    },
  },
  onReachBottom() {
    if (!this.noMore) {
      this.page++;
      this.getList();
    }
  },
};
</script>

<style lang="scss" scoped>
.checkShop {
  min-height: 100vh;
  padding-top: 160rpx;
  background-color: #f2f2f2;
  font-family: PingFang SC;
  color: #262626;
}
.header-tabs {
  width: 100%;
  padding-top: 20rpx;
  height: 90rpx;
  // line-height: 90rpx;
  background: #ffffff;
  position: fixed;
  top: 0;
  z-index: 1000;
  left: 0;
}
.shopList {
  .shopItem {
    background-color: #fff;
    padding: 30rpx;
    margin-top: 24rpx;
    .title {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .name {
        display: flex;
        font-size: 28rpx;
        font-weight: 600;
        .iconfont {
          font-size: 36rpx;
          font-weight: normal;
          margin-right: 6rpx;
        }
      }
      .status {
        font-size: 24rpx;
        color: #f0250e;
      }
    }
    .info {
      margin-top: 10rpx;
      display: flex;
      flex-direction: column;
      font-size: 28rpx;
      text:nth-child(2) {
        font-size: 24rpx;
        color: #8c8c8c;
        margin-top: 10rpx;
      }
    }
    .btns {
      margin-top: 30rpx;
      display: flex;
      justify-content: flex-end;
      text {
        width: 152rpx;
        height: 60rpx;
        line-height: 60rpx;
        text-align: center;
        border-radius: 99rpx;
        font-size: 26rpx;
        border: 1px solid #a1a1a1;
        margin-left: 24rpx;
      }
      .red {
        color: #f0250e;
        border: 1px solid #f0250e;
      }
    }
  }
}
.tabs {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 94rpx;
  background-color: #fff;
  align-items: center;
  padding: 0 24rpx;
  font-size: 28rpx;
  color: #8c8c8c;
  font-weight: 600;
  .tabItem {
    margin-right: 44rpx;
    padding-bottom: 10rpx;
  }
  .choosed {
    color: #262626;
    font-size: 32rpx;
    position: relative;
  }
  .choosed::before {
    content: '';
    position: absolute;
    width: 40rpx;
    height: 6rpx;
    background-color: #f0250e;
    left: 50%;
    bottom: -6rpx;
    transform: translateX(-50%);
  }
}
.query {
  position: fixed;
  top: 94rpx;
  left: 0;
  width: 100%;
  height: 66rpx;
  background-color: #f2f2f2;
  display: flex;
  align-items: center;
  font-size: 24rpx;
  color: #666;
  padding: 0 22rpx;
  .queryItem {
    display: flex;
    align-items: center;
    margin-right: 60rpx;
    .iconfont {
      font-size: 18rpx;
      color: #dbdbdb;
      margin-left: 8rpx;
    }
  }
  .choosed {
    color: #f0250e;
    .iconfont {
      color: #f0250e;
    }
  }
}
.chooseBox {
  position: fixed;
  width: 100%;
  height: calc(100vh - 160rpx);
  top: 160rpx;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  .options {
    width: 100%;
    border-radius: 0 0 20rpx 20rpx;
    background-color: #fff;
    padding: 20rpx 24rpx;
    .optionItem {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20rpx 0;
      font-size: 28rpx;
      .iconfont {
        font-size: 48rpx;
      }
    }
    .choosed {
      color: #f0250e;
    }
  }
}
</style>
